package com.polaris.live.utils.popup_animator

import android.view.animation.OvershootInterpolator
import androidx.interpolator.view.animation.FastOutSlowInInterpolator
import com.lxj.xpopup.animator.PopupAnimator

/**
 * 今日特价礼物动画
 *
 * @author Created by 半仙 on 2023/11/28/028 17:45
 */
class RechargeAnimator : PopupAnimator() {

    private val startScale = 0f
    override fun initAnimator() {
        targetView.scaleX = startScale
        targetView.scaleY = startScale

        // 设置动画参考点

        // 设置动画参考点
        targetView.post { applyPivot() }
    }

    private fun applyPivot() {
        if (targetView == null) {
            return
        }

        targetView.pivotX = targetView.measuredWidth / 2f
        targetView.pivotY = targetView.measuredHeight / 2f
    }

    override fun animateShow() {
        targetView.post {
            if (targetView == null) {
                return@post
            }
            targetView.animate().scaleX(1f).scaleY(1f)
                .setDuration(610)
                .setInterpolator(OvershootInterpolator(1.7f))
                .start()
        }
    }

    override fun animateDismiss() {
        observerAnimator(
            targetView.animate().scaleX(.95f).scaleY(.95f).alpha(0f)
                .setDuration(200L)
                .setInterpolator(FastOutSlowInInterpolator())
        ).start()
    }

}